﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Role.aspx.cs" Inherits="Meeting.Web.Admin.BaseSet.Role" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>角色管理</title>
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../Css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            //初始化列表
            $('#mainList').datagrid({
                url: 'RoleOperation.aspx.ashx?method=GetRole',
                singleSelect: true,
                collapsible: false,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        OpenWin();
                    }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        EditData();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        $.messager.confirm('警告', '该记录将被永久删除，确定吗?', function (e) {
                            if (!e) return;
                            DeleteData();
                        })
                    }
                }]
            });
            //设置分页
            var p = $("#mainList").datagrid("getPager");
            $(p).pagination({
                pageSize: 10, //每页显示的记录条数，默认为10   
                pageList: [5, 10, 15], //可以设置每页记录条数的列表   
                beforePageText: '第', //页数文本框前显示的汉字   
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
            });
        });

        //打开窗口
        function OpenWin() {
            $("#Id").val('');
            $('#Name').val('');
            $("#Comment").val('');
            $("#edit").dialog("open").dialog('setTitle', '新增角色');
        }
        //保存数据
        function AddData() {
            if ($("#editForm").form('validate') == false) {
                return;
            }
            var Id = $("#Id").val();
            var Name = $("#Name").val();
            var Comment = $("#Comment").val();
            var postData = { Id: Id, Name: Name, Comment: Comment };
            //提交
            $.post("RoleOperation.ashx?method=RoleEdit", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", '添加成功');
                    $("#mainList").datagrid('reload');
                    $("#edit").dialog("close");
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });
        }
        //edit
        function EditData() {
            var row = $('#mainList').datagrid('getSelected');
            if (!row) {
                parent.$.messager.alert("提示", '请选择您要修改的记录！');
                return;
            }
            //
            $("#Id").val(row.Id);
            $('#Name').val(row.Name);
            $("#Comment").val(row.Comment);
            //打开窗口
            $('#edit').window('open').dialog("setTitle", "编辑角色");
        }
        //delete
        function DeleteData() {
            var row = $('#mainList').datagrid('getSelected');
            if (!row) {
                $.messager.alert("提示", '请选择您要删除的记录！');
                return;
            }
            var postData = { id: row.Id };
            $.post("RoleOperation.ashx?method=Delete", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", '删除成功');
                    $("#mainList").datagrid('reload');
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });
        }
         
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="float: left; width: 15%; margin-top: 3px; min-height: 600px; height: 100%">
        <table id="mainList" class="easyui-datagrid" style="width: 844px;">
            <thead>
                <tr>
                    <th data-options="field:'Id',width:120">
                        角色编号
                    </th>
                    <th data-options="field:'Name',width:120">
                        角色名称
                    </th>
                </tr>
            </thead>
        </table>
    </div>
    </form>
    <div id="edit" class="easyui-dialog" title="编辑角色" style="width: 400px; height: 260px;"
        modal="true" closed="true" buttons="#edit-buttons">
        <form id="editForm" >
        <table class="table_edit" style=" ">
            <tr>
                <td class="tdName">
                    角色编号:
                </td>
                <td class="tdText">
                    <input id="Id" name="Id" style="width: 150px;" class="easyui-validatebox" required="true" />
                </td>
            </tr>
            <tr>
               <td class="tdName">
                    角色名称:
                </td>
                <td>
                    <input id="Name" name="Name" style="width: 153px;" class="easyui-validatebox" required="true" />
                </td>
            </tr>
            <tr>
               <td class="tdName">
                    备注:
                </td>
                <td>
                    <input id="Comment" name="Comment" style="width: 150px;" class="easyui-validatebox"
                        type="text" />
                </td>
            </tr>
        </table>
        <div id="edit-buttons">
            <a id="A1" href="#" onclick="InitData();" class="easyui-linkbutton">新增+</a> <a id="btn_add"
                href="#" onclick="AddData(1);" class="easyui-linkbutton">保存</a> <a id="del" href="#"
                    onclick="DelData();" class="easyui-linkbutton">删除-</a>
        </div>
        </form>
    </div>
</body>
</html>
